//
//  XGPushHandler.swift
//  TestWorkSpace
//
//  Created by Mac on 2020/1/7.
//  Copyright © 2020 jhf. All rights reserved.
//

import UIKit

class XGPushHandler: NSObject, XGPushDelegate {
    
    static let shared = XGPushHandler()
    
    func configXGPush(launchOptions: [UIApplication.LaunchOptionsKey: Any]) {
        XGPush.defaultManager().startXG(withAppID: 2200351647, appKey: "IT6V236TA8XG", delegate: self)
        XGPush.defaultManager().reportXGNotificationInfo(launchOptions)
    }
    
    func xgPush(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse?, withCompletionHandler completionHandler: @escaping () -> Void) {
        log.debug(response ?? "")
        
        if let name = response?.notification.request.content.userInfo["name"] as? String {
            print("I know it's you! \(name)")
        }
        
        XGPush.defaultManager().reportXGNotificationResponse(response)
        completionHandler()
    }
    
    func xgPush(_ center: UNUserNotificationCenter, willPresent notification: UNNotification?, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        log.debug(notification ?? "")
        XGPush.defaultManager().reportXGNotificationInfo((notification?.request.content.userInfo)!)
        completionHandler(UNNotificationPresentationOptions(rawValue: UNNotificationPresentationOptions.alert.rawValue | UNNotificationPresentationOptions.sound.rawValue | UNNotificationPresentationOptions.badge.rawValue))
    }
    
}
